let emoji = {
  list: [
    { txt: '[鲜花]', img: require('./鲜花.png'), src: 'https://qiniuoss.chenxi618.com/liveVideoEmoji%E9%B2%9C%E8%8A%B1.png' },
    { txt: '[掌声]', img: require('./掌声.png'), src: 'https://qiniuoss.chenxi618.com/liveVideoEmoji%E6%8E%8C%E5%A3%B0.png' },
    { txt: '[看涨]', img: require('./看涨.png'), src: 'https://qiniuoss.chenxi618.com/liveVideoEmoji%E7%9C%8B%E6%B6%A8.png' },
    { txt: '[看跌]', img: require('./看跌.png'), src: 'https://qiniuoss.chenxi618.com/liveVideoEmoji%E7%9C%8B%E8%B7%8C.png' },
    { txt: '[震荡]', img: require('./震荡.png'), src: 'https://qiniuoss.chenxi618.com/liveVideoEmoji%E9%9C%87%E8%8D%A1.png' },
  ]
};

let ruleStr = new RegExp(
  emoji.list.reduce((t, v, i) => {
    let str = v.txt.replace(/\[/, '(\\[').replace(/\]/, '\\])')
    return t + (i == 0 ? '' : '|') + str
  }, '')
  , 'g'
)

let emojiReplace = function (str) {
  if (str.length == 0 || typeof (str) != 'string') { return '' }
  let ret = str.replace(ruleStr, function (m) {
    let item = emoji.list.find((v) => { return v.txt == m });
    return `<img src="${item.img}" alt="${item.txt}">`;
  })
  return ret;
}

let ruleImg = new RegExp(/<img src=".+?" alt="\[(.+?)\]">/, 'g');
let imgReplaceEmoji = function (html) {
  let r = html.replace(ruleImg, function (m, p1, p2) {
    return '[' + p1 + ']';
  })
  return r
}

export {
  emoji, ruleStr, emojiReplace, ruleImg, imgReplaceEmoji
}